<?php
	namespace Home\Model;
	use Think\Model;
	header("Content-Type: text/html; charset=utf-8");
	class UserModel extends Model{
		protected $_validate = array( 
  		
        array('status',array(1),'值的范围不正确！',2,'in'),
        // 当值不为空的时候判断是否在一个范围内
        array('repassword','password','确认密码不正确',0,'confirm'), 
        // 验证确认密码是否和密码一致 
        array('password','checkPwd','密码格式不正确',0,'function'), 
        // 自定义函数验证密码格式);


			);
		protected $_auto=array(
			array('pwd','md5',3,'function'),
			array('status',0),
			array('regtime','time',1,'function')

			);


		public function getFind($data){
			$res=$this->where($data)->find();
			return $res;
		}
		public function getAdd($data){
			$this->startTrans();
			$res=$this->data($data)->add();

			$UiModel = M('userInfo');
			$result = $UiModel->add(['uid'=>$res]);
			if($res&&$result){
				$this->commit();
				return true;
			}else
			{
				$this->rollback();
				return false;
			}
		}
		public function getuser($id){
			$list=$this->field('u.sex ux,u.id uid,u.name uname,uf.id ufd,uf.uid ufuid,uf.age ufg,uf.tel uft,uf.birthday ufb,uf.email ufe,uf.qq ufq,uf.name ufn, uf.face uff ')->table('user  u,user_info uf')->where("u.id=uf.uid and u.id=".$id)->find();
				$list['ux']=$list['ux']?'男':'女';		
			return $list;
		}
		public function rset($data,$npwd){
			$res=$this->where($data)->find();
			if (!empty($res)) {
				$data['pwd']=md5(htmlspecialchars(trim($npwd,'')));
				$id=$data['id'];
				unset($data['name']);
				unset($data['id']);
				$res=$this->where('id='.$id)->save($data);
				return $res;
			}else{
				return 3;
			}
		}
	}

	